﻿<!DOCTYPE html>
<html lang="en">
<head th:replace="~{parts/head}">

<!-- page wrapper -->
<body>

    <div class="boxed_wrapper">

        <!-- preloader -->
        <div class="preloader"></div>
        <!-- preloader -->


        <!-- main header -->
        <header class="main-header style-three">

            <!-- header-lower -->
            <div class="header-lower">
                <div class="outer-box clearfix">
                    <div class="left-column">
                        <div class="logo-box">
                            <figure class="logo"><a href="/"><img src="../../images/logo-3.png" alt=""></a></figure>
                        </div>
                        <div th:replace="~{parts/menu-area}">
                        </div>
                        <div class="right-column pull-right">
                            <div th:replace="~{parts/author-box}">
                            </div>
                        </div>
                    </div>

                    <!--sticky Header-->
                    <div class="sticky-header">
                        <div class="auto-container">
                            <div class="outer-box">
                                <div class="logo-box">
                                    <figure class="logo"><a href="/"><img src="../../images/small-logo.png" alt=""></a></figure>
                                </div>
                                <div class="menu-area">
                                    <nav class="main-menu clearfix">
                                        <!--Keep This Empty / Menu will come through Javascript-->
                                    </nav>
                                </div>
                                <!--                        <div class="btn-box"><a href="register-page.html" class="theme-btn-one"><i class="icon-image"></i>Join Now</a></div>-->
                            </div>
                        </div>
                    </div>
        </header>
        <!-- main-header end -->

        <!-- Mobile Menu  -->
        <div class="mobile-menu">
            <div class="menu-backdrop"></div>
            <div class="close-btn"><i class="fas fa-times"></i></div>
            
            <nav class="menu-box">
                <div class="nav-logo"><a href="/"><img src="../../images/logo-2.png" alt="" title=""></a></div>
                <div class="menu-outer"><!--Here Menu Will Come Automatically Via Javascript / Same Menu as in Header--></div>
                <div class="contact-info">
                    <h4>Contact Info</h4>
                    <ul>
                        <li>Chicago 12, Melborne City, USA</li>
                        <li><a href="">+88 01682648101</a></li>
                        <li><a href="mailto:info@example.com">info@example.com</a></li>
                    </ul>
                </div>
                <div class="social-links">
                    <ul class="clearfix">
                        <li><a href="/"><span class="fab fa-twitter"></span></a></li>
                        <li><a href="/"><span class="fab fa-facebook-square"></span></a></li>
                        <li><a href="/"><span class="fab fa-pinterest-p"></span></a></li>
                        <li><a href="/"><span class="fab fa-instagram"></span></a></li>
                        <li><a href="/"><span class="fab fa-youtube"></span></a></li>
                    </ul>
                </div>
            </nav>
        </div><!-- End Mobile Menu -->


        <!--page-title-two-->
        <section class="page-title-two">
            <div class="title-box centred bg-color-2">
                <div class="pattern-layer">
                    <div class="pattern-1" style="background-image: url(../../images/shape/shape-70.png);"></div>
                    <div class="pattern-2" style="background-image: url(../../images/shape/shape-71.png);"></div>
                </div>
                <div class="auto-container">
                    <div class="title">
                        <h1>预约挂号</h1>
                    </div>
                </div>
            </div>
            <div class="lower-content">
                <div class="auto-container">
                    <ul class="bread-crumb clearfix">
                        <li><a href="/">主页</a></li>
                        <li><a style="cursor: pointer" onclick="window.history.back(-1);">上一页</a></li>
                        <li>预约挂号</li>
                    </ul>
                </div>
            </div>
        </section>
        <!--page-title-two end-->


        <!-- appointment-section -->
        <section class="appointment-section bg-color-3">
            <div class="auto-container">
                <div class="row clearfix">
                    <div class="col-lg-12 col-md-12 col-sm-12 left-column">
                        <div class="appointment-information">
                            <div class="title-box">
                                <h3>预约详情</h3>
                            </div>
                            <div class="inner-box">
                                <div class="information-form">
                                    <h3>科室信息:</h3>
                                    <span class="d-none" id="patId" th:text="${patient.id}"></span>
                                    <div class="row clearfix">
                                        <div class="col-lg-6 col-md-12 col-sm-12 form-group">
                                            <select class="wide" id="clinicId">
                                                <option data-display="选择科室">选择科室</option>
                                                <option th:each="item:${clinics}" th:text="${item.name}" th:value="${item.id}">Select Text 01</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="information-form">
                                    <h3>预约信息:</h3>
                                    <form action="book-appointment.html" method="post">
                                        <div class="row clearfix">
                                            <div class="col-lg-12 col-md-12 col-sm-12 form-group">
                                            <p>
                                                <th:block th:each="item,stat:${dateMap}">
                                                    <a class="theme-btn" onclick="switchCollapse(this)">
                                                        <span th:text="${item.value[0]}" style="display: none"></span>
                                                        <span th:text="${item.value[1]}"></span>
                                                    </a>
                                                </th:block>
                                            </p>
                                            <div id="doc-info">
                                                <div th:fragment="doc-info">
                                                    <div class="collapse" id="collapse">
                                                        <div class="card card-body" style="margin-top: 10px;" th:each="item:${doctors}">
                                                            <div class="row">
                                                                <div class="col-lg-2">
                                                                    <figure class="image" style="float: left;"><img th:src="${item.icon}" alt="" style="border-radius: 50%;overflow: hidden;width: 100px;"></figure>
                                                                </div>
                                                                <div class="col-lg-3" style="margin-top: 10px;">
                                                                    <h5 th:text="${item.name}">李钱容</h5>
                                                                    <p th:text="${item.formatLevel}">主治医师</p>
                                                                </div>
                                                                <div class="col-lg-4"></div>
                                                                <div class="col-lg-3 text-right">
                                                                    <a class="theme-btn-1" onclick="showPeriod(this)">
                                                                        <span th:text="${item.id}" style="display: none"></span>
                                                                        <span th:text="${item.stage}" style="display: none"></span>
                                                                        <span th:text="${item.formatStage}">上午</span> | <span th:text="${item.formatAppBtnText}">有号</span>
                                                                    </a>
                                                                </div>
                                                                <div class="col-lg-12">
                                                                    <p th:text="${item.intro}">擅长：妊娠期保健、妊娠并发症与合并症的诊治、美容切口剖宫产术。在前置胎盘、胎盘早剥、产后出血等并发症的诊治方面积累了丰富的临床经验。</p>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="card card-body" style="margin-top: 10px;" th:if="${doctors eq null or doctors.size eq 0}">
                                                            <div class="row">
                                                                <div class="col-lg-12">
                                                                    <p>当日无号</p>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            </div>
                                        </div>
                                    </form>

                                </div>
                            </div>
                        </div>
                    </div>
<!--                    <div class="col-lg-4 col-md-12 col-sm-12 right-column">-->
<!--                        <div class="booking-information">-->
<!--                            <div class="title-box">-->
<!--                                <h3>预约信息</h3>-->
<!--                            </div>-->
<!--                            <div class="inner-box">-->
<!--                                <div class="single-box">-->
<!--                                    <ul class="clearfix">-->
<!--                                        <li>预约日期<span id="appointmentDateCopy"></span></li>-->
<!--                                        <li>医生姓名<span id="docNm"></span></li>-->
<!--                                    </ul>-->
<!--                                </div>-->
<!--                                <div class="single-box">-->
<!--                                    <ul class="clearfix">-->
<!--                                        <li>挂号费<span id="priceCopy"></span></li>-->
<!--                                    </ul>-->
<!--                                </div>-->
<!--                                <div class="total-box">-->
<!--                                    <h5>合计<span id="price"></span></h5>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="btn-box">-->
<!--                                <a style="cursor:pointer;" class="theme-btn-one" onclick="save()">确认提交预约<i class="icon-Arrow-Right"></i></a>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
                </div>
            </div>
        </section>
        <!-- appointment-section end -->


        <!-- agent-section -->
        <section class="agent-section bg-color-3">
            <div class="auto-container">
                <div class="inner-container bg-color-2">
                    <div th:replace="~{parts/agent-section}"></div>
                </div>
            </div>
        </section>
        <!-- agent-section -->


        <!-- main-footer -->
        <div th:replace="~{parts/main-footer}"></div>
        <!-- main-footer end -->
        <div th:replace="~{parts/alert-modal}"></div>

        <!-- 模态框 -->
        <div class="modal fade" id="appModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <!-- 模态框头部 -->
                    <div class="modal-header">
                        <h4 class="modal-title">选择挂号时间段</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <!-- 模态框主体 -->
                    <div class="modal-body" id="appModalBody">
                        <div class="input-group mb-3" th:fragment="period">
                            <div class="input-group-prepend" style="height: 40px">
                                <label class="input-group-text" for="period">时间段</label>
                            </div>
                            <select class="custom-select" id="period" style="height: 40px">
                                <option data-display='选择时间段'>选择时间段</option>
                                <option th:each="item,stat:${periodList}" th:value="${periodIdList[stat.index]}" th:text="${item}"></option>
                            </select>
                        </div>
                    </div>
                    <!-- 模态框底部 -->
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="showPay()">确定</button>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 模态框 -->
        <div class="modal fade" id="payModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <!-- 模态框头部 -->
                    <div class="modal-header">
                        <h4 class="modal-title">支付费用</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <!-- 模态框主体 -->
                    <div class="modal-body">
                        <div class="text-center">
                            <p>挂号信息完成锁号，请在5分钟内支付，否则订单失效！</p>
                            <p>支付后需等待信息反馈，若消息提示成功方可认为挂号成功，若失败，费用会24小时原路返回，若没有消息返回需等待确认</p>
                            <p>请支付挂号费：14元</p>
                            <img src="../../images/pay.png" style="height: 370px">
                        </div>
                    </div>
                    <!-- 模态框底部 -->
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="save(true)">支付</button>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="save(false)">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 模态框 -->
        <div class="modal fade" id="paySuccessModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <!-- 模态框头部 -->
                    <div class="modal-header">
                        <h4 class="modal-title">通知</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <!-- 模态框主体 -->
                    <div class="modal-body">
                        支付成功
                    </div>
                    <!-- 模态框底部 -->
                    <div class="modal-footer">
                        <!--        <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>-->
                        <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="window.location.reload();">关闭</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 模态框 -->
        <div class="modal fade" id="payFailModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <!-- 模态框头部 -->
                    <div class="modal-header">
                        <h4 class="modal-title">通知</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <!-- 模态框主体 -->
                    <div class="modal-body">
                        支付失败
                    </div>
                    <!-- 模态框底部 -->
                    <div class="modal-footer">
                        <!--        <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>-->
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="payBanedModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <!-- 模态框头部 -->
                    <div class="modal-header">
                        <h4 class="modal-title">通知</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <!-- 模态框主体 -->
                    <div class="modal-body">
                        多次支付失败，账号禁用
                    </div>
                    <!-- 模态框底部 -->
                    <div class="modal-footer">
                        <!--        <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>-->
                        <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="window.location.href='/login';">关闭</button>
                    </div>
                </div>
            </div>
        </div>

        <!--Scroll to top-->
        <button class="scroll-top scroll-to-target" data-target="html" onclick='location.href=("/message?targetId=6")'>
            <img src="../../images/robot-2.png">
        </button>
    </div>

    <script th:replace="~{parts/js}"></script>
    <script>
        $('#pat_tab').addClass("current");
        // $("#appointmentDate").datetimepicker({
        //     format: 'yyyy/mm/dd',
        //     autoclose: true,
        //     language: 'zh-CN',
        //     minView: 2,
        //     initialDate: new Date()
        // });
        // $('#appointmentDate')
        //     .datetimepicker()
        //     .on('changeDate', function(ev){
        //         $('#appointmentDateCopy').text($('#appointmentDate').val());
        //     });
        // $("#docId").on("change", function () {
        //     $('#docNm').text($('#docId').find("option:selected").text());
        //     $('#price').text('￥50');
        //     $('#priceCopy').text('￥50');
        // });
        function save(flg) {
            $.ajax({
                type: "post",
                url:"/book-appointment/save",
                cache: false,
                data: {
                    clinicId: $('#clinicId').val(),
                    docId: docId,
                    appointmentDate: appDate,
                    period: $('#period').val(),
                    stage: stage,
                    price: 14,
                    stateId: flg ? '1' : '0'
                },
                success: function (data) {
                    if (data.state === "success") {
                        $('#paySuccessModal').modal('show');
                    } else if (data.state === "baned") {
                        $('#payBanedModal').modal('show');
                    } else {
                        $('#payFailModal').modal('show');
                    }
                },
                error: function(res) {
                    $('#payFailModal').modal('show');
                }
            });
        }
        let appDate = '';
        let docId = '';
        let stage = 0;
        function switchCollapse(item) {
            appDate = $(item).children(":first").text();
            $.ajax({
                type: "get",
                url:"/book-appointment/getDocData",
                cache: false,
                data: {
                    clinicId: $('#clinicId').val(),
                    date: appDate
                },
                success: function (data) {
                    $('#doc-info').html(data);
                    $('#collapse').show();
                },
                error: function(res) {
                    $('#handleFailModal').modal('show');
                }
            });
        }
        function showPeriod(item) {
            docId = $(item).find(':nth-child(1)').text();
            stage = $(item).find(':nth-child(2)').text();
            $.ajax({
                type: "post",
                url:"/book-appointment/getAppData",
                cache: false,
                data: {
                    clinicId: $('#clinicId').val(),
                    date: appDate,
                    docId: docId,
                    stage: stage
                },
                success: function (data) {
                    $('#appModalBody').html(data);
                    $('#appModal').modal('show');
                },
                error: function(res) {
                    $('#handleFailModal').modal('show');
                }
            });

        }
        function showPay() {
            $('#payModal').modal('show');
        }
    </script>
    <style type="text/css">
        ul.list {
            width: 100%;
            height: 160px;
            overflow-y: scroll !important;
        }
        .nice-select {
            border: solid 1px #e8e8e8 !important;
        }
        #appModal .nice-select {
            height: 40px;
            padding: 0;
        }
        #appModal .nice-select:after {
            top: 5px;
        }
        #appModal .current {
            margin-left: 10px;
        }
        .theme-btn {
            position: relative;
            display: inline-block;
            font-size: 15px;
            line-height: 26px;
            font-weight: 600;
            color: #fff !important;
            background: #39cabb;
            text-align: center;
            padding: 15px 19.5px;
            border-radius: 5px;
            z-index: 1;
            transition: all 500ms ease;
            cursor:pointer;
        }
        .theme-btn-1 {
            position: relative;
            display: inline-block;
            font-size: 15px;
            line-height: 26px;
            font-weight: 600;
            color: #fff !important;
            background: #39cabb;
            text-align: center;
            padding: 4px 6px;
            border-radius: 5px;
            z-index: 1;
            transition: all 500ms ease;
            cursor:pointer;
        }
    </style>
</body><!-- End of .page_wrapper -->
</html>
